package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.pojo.Order;
import com.itheima.pojo.Page;
import com.itheima.service.OrdersService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @author wuyiqiang
 * @2022/6/16 16:44
 */
@RestController
@RequestMapping(value="/order",produces = "application/json;charset=utf-8")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 通过订单号查询订单
     * @param page
     * @param pageSize
     * @param number
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping("/page")
    public R<Page> page(@Param("page") int page,@Param("pageSize") int pageSize,@Param("number") String number, @Param("beginTime") String beginTime,@Param("endTime") String endTime) throws ParseException {
      return   ordersService.page(page,pageSize,number,beginTime,endTime);
    }

    /**
     * 更改订单状态
     *
     * @param
     * @param
     * @return
     */
    @PutMapping
    public R status(@RequestBody Order order) {

        ordersService.status(order.getStatus(),order.getId());
        return R.success("修改成功");
    }
}
